package com.zide.framework.web.mapper;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zide.common.core.domain.PageResult;
import com.zide.framework.config.mybatisplus.XianYingMapperPlus;
import com.zide.common.core.domain.SysOperLog;
import com.zide.framework.web.domain.operlog.vo.SysOperLogSearchVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 操作日志 数据层
 *
 * @author zide
 */
@Mapper
public interface SysOperLogMapper extends XianYingMapperPlus<SysOperLog> {

    default PageResult<SysOperLog> selectPage(SysOperLogSearchVO searchVO) {
        LambdaQueryWrapper<SysOperLog> wrapper = new LambdaQueryWrapper<>();

        if(ObjectUtil.isNotNull(searchVO.getStatus())) {
            wrapper.eq(SysOperLog::getStatus,searchVO.getStatus());
        }

        if(ObjectUtil.isNotNull(searchVO.getBusinessType())) {
            wrapper.eq(SysOperLog::getBusinessType,searchVO.getBusinessType());
        }

        if(StrUtil.isNotEmpty(searchVO.getOperIp())) {
            wrapper.like(SysOperLog::getOperIp,searchVO.getOperIp());
        }

        if(StrUtil.isNotEmpty(searchVO.getOperName())) {
            wrapper.like(SysOperLog::getOperName,searchVO.getOperName());
        }

        if(ObjectUtil.isNotNull(searchVO.getOperatorType())) {
            wrapper.eq(SysOperLog::getOperatorType,searchVO.getOperatorType());
        }

        if(StrUtil.isNotEmpty(searchVO.getTitle())) {
            wrapper.like(SysOperLog::getTitle,searchVO.getTitle());
        }
        return selectPage(searchVO, wrapper);
    }

    /**
     * 新增操作日志
     *
     * @param operLog 操作日志对象
     */
    public void insertOperlog(SysOperLog operLog);

    /**
     * 查询系统操作日志集合
     *
     * @param operLog 操作日志对象
     * @return 操作日志集合
     */
    public List<SysOperLog> selectOperLogList(SysOperLog operLog);

    /**
     * 批量删除系统操作日志
     *
     * @param operIds 需要删除的操作日志ID
     * @return 结果
     */
    public int deleteOperLogByIds(Long[] operIds);

    /**
     * 查询操作日志详细
     *
     * @param operId 操作ID
     * @return 操作日志对象
     */
    public SysOperLog selectOperLogById(Long operId);

    /**
     * 清空操作日志
     */
    public void cleanOperLog();
}
